package com.x.wx.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;
import com.x.wx.model.WxKeyword;
import com.x.wx.rpc.WxKeywordRpcService;
import org.springframework.web.bind.annotation.RestController;



/**
 * 关键字菜单
 */
@RestController
@RequestMapping("/wxKeyword")
public class WxKeywordController extends BaseController {

    @Reference
    private WxKeywordRpcService wxKeywordRpcService;


    @RequestMapping(value= "/selectWxKeywordList", method = { RequestMethod.POST, RequestMethod.GET })
    public ResultModel selectWxKeywordList(WxKeyword wxKeyword) {
        if(StringUtils.isEmpty(wxKeyword.getAccountId())){
            return new ResultModel(ResultCode.RESULT_FAIL, "公众号ID不能为空！");
        }
        return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功",  wxKeywordRpcService.selectWxKeywordList(wxKeyword));
    }


    @RequestMapping(value="/insertWxKeyword" , method = {RequestMethod.POST, RequestMethod.GET})
    public ResultModel insertWxKeyword(WxKeyword wxKeyword) {
        if(StringUtils.isEmpty(wxKeyword.getAccountId())){
            return new ResultModel(ResultCode.RESULT_FAIL, "公众号ID不能为空！");
        }
    	WxKeyword insertWxKeyword = wxKeywordRpcService.insertWxKeyword(wxKeyword);
        return new ResultModel(ResultCode.RESULT_SUCCESS, "插入成功！", insertWxKeyword);
    }


    @RequestMapping(value= "/updateWxKeyword",method = {RequestMethod.POST, RequestMethod.GET} )
    public ResultModel updateWxKeyword(WxKeyword wxKeyword) {
        if(StringUtils.isEmpty(wxKeyword.getAccountId())){
            return new ResultModel(ResultCode.RESULT_FAIL, "公众号ID不能为空！");
        }
    	int updateWxKeyword = wxKeywordRpcService.updateWxKeyword(wxKeyword);
        return new ResultModel(ResultCode.RESULT_SUCCESS, "更新成功！", updateWxKeyword);
    }


    @RequestMapping(value= "/deleteWxKeyword", method = {RequestMethod.POST, RequestMethod.GET})
    public ResultModel deleteWxKeyword(WxKeyword wxKeyword) {
        if(StringUtils.isEmpty(wxKeyword.getAccountId())){
            return new ResultModel(ResultCode.RESULT_FAIL, "公众号ID不能为空！");
        }
    	int deleteWxKeyword = wxKeywordRpcService.deleteWxKeyword(wxKeyword);
        return new ResultModel(ResultCode.RESULT_SUCCESS, "删除成功！", deleteWxKeyword);
    }

    @RequestMapping(value= "/selectWxKeywordNum", method = {RequestMethod.POST, RequestMethod.GET})
    public ResultModel selectWxKeywordNum(WxKeyword wxKeyword) {
        if(StringUtils.isEmpty(wxKeyword.getAccountId())){
            return new ResultModel(ResultCode.RESULT_FAIL, "公众号ID不能为空！");
        }
    	Map<String, Object> res = new HashMap<>();
    	res.put("total", wxKeywordRpcService.selectWxKeywordNum(wxKeyword));
        return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功！", res);
    }

}
